package com.onpositive.data.kvstorage;

import com.onpositive.data.IPropertyMetadata;
import com.onpositive.datamap.item.SingleDataObject;

public abstract class DefaultKeyValueCollectionCreator implements IKeyValueCollectionCreator{

	public abstract IKeyValueAccess access(String key);
	
	@Override
	public abstract String alloc(String name) ;

	@Override
	public void addProperty(String key, IPropertyMetadata m) {
		KeyValueBasedCollection keyValueBasedCollection = new KeyValueBasedCollection(access(key));
		if (keyValueBasedCollection.getProperty(m.id())==null){
			keyValueBasedCollection.addMetadata(m);
			keyValueBasedCollection.store();
		}
	}

	@Override
	public void store(String key, SingleDataObject object) {
		KeyValueBasedCollection keyValueBasedCollection = new KeyValueBasedCollection(access(key));
		keyValueBasedCollection.storeObject(object);
	}

	@Override
	public void storeIndex(String key, String id, Object[] values) {
		KeyValueBasedCollection keyValueBasedCollection = new KeyValueBasedCollection(access(key));
		keyValueBasedCollection.setIndex(id, values);
	}

	@Override
	public DataCollectionInfo commit(String key,DataCollectionInfo info) {
		return info;
	}

	@Override
	public void rollback(String key) {
		
	}

}
